// app.js
App({
  // 引入`towxml3.0`解析方法
  towxml: require('/towxml/index'),
  onLaunch() {
    this.getSystemInfo();
    this.getAccountInfor();

    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      this.shareData();
    }
  },

  // 共享数据库
  async shareData() {
    var c1 = new wx.cloud.Cloud({
      resourceAppid: "wx9a44ab6c8170142c",
      resourceEnv: "love-0g1b6yqybf5521f5",
    });
    await c1.init();

    await c1.callFunction({
      name: 'get',
      data: {},
      success: res => {
        console.log(res);
      }
    })

  },

  getSystemInfo() {
    const that = this;
    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    // 导航栏高度 = 状态栏高度 + 44
    that.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
    that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
    that.globalData.menuTop = menuButtonInfo.top;
    that.globalData.menuBotton = menuButtonInfo.top - systemInfo.statusBarHeight;
    that.globalData.menuHeight = menuButtonInfo.height;
  },

  getAccountInfor() {
    const { miniProgram: { envVersion } } = wx.getAccountInfoSync();
    this.globalData.hide = true
    switch (envVersion) {
      case 'develop':
        this.globalData.hide = false;
        break;
      case 'trial':
        this.globalData.hide = true;
        break;
      case 'release':
        this.globalData.hide = false;
        break;
      default:
        this.globalData.hide = false;
        break;
    }
  },

  globalData: {
    hide: false,
    navBarHeight: 0, // 导航栏高度
    menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
    menuTop: 0, // 胶囊距上方间距
    menuBotton: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
  }
})
